package com.bsc.rtc.lib.libraries.WebViewDemos;

import android.annotation.SuppressLint;
import android.net.Uri;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.bsc.rtc.lib.libraries.R;

import java.util.Map;

public class MWebViewActivity extends AppCompatActivity {
    private String TAG = "MWebViewActivity";
    WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mweb_view);
        initWebView();
    }


    private void initWebView() {
        webView = findViewById(R.id.mWebView);
        webView.loadUrl("");
        webView.setWebViewClient(new WebViewClient() {


            @SuppressLint("NewApi")
            @Override
            public WebResourceResponse shouldInterceptRequest(WebView view, final WebResourceRequest request) {
                return super.shouldInterceptRequest(view, new WebResourceRequest() {
                    @Override
                    public Uri getUrl() {
                        return Uri.parse("https://www.jianshu.com/p/c7f0eca81955");
                    }

                    @SuppressLint("NewApi")
                    @Override
                    public boolean isForMainFrame() {
                        return request.isForMainFrame();
                    }

                    @Override
                    public boolean isRedirect() {
                        return false;
                    }

                    @SuppressLint("NewApi")
                    @Override
                    public boolean hasGesture() {
                        return request.hasGesture();
                    }

                    @SuppressLint("NewApi")
                    @Override
                    public String getMethod() {
                        return request.getMethod();
                    }

                    @SuppressLint("NewApi")
                    @Override
                    public Map<String, String> getRequestHeaders() {
                        return request.getRequestHeaders();
                    }
                });
            }
        });


    }
}
